/**
 * related to detail.ui 商品详情
 *
 */
var root = ui("$");
var app = sm("do_App");
var page = sm("do_Page");
var hashdata = mm("do_HashData");
var global = sm("do_Global");
var nf = sm("do_Notification");
var productNameLabel = ui("productNameLabel");
var priceLabel = ui("priceLabel");
var unitLabel = ui("unitLabel");
var marketPriceLabel = ui("marketPriceLabel");
var labelSindex = ui("labelSindex");
var lableScount = ui("lableScount");
var imgView = ui("do_SlideView_1");
var labelSubtitle = ui("labelSubtitle");
var imgData = mm("do_ListData");
var shareHelper = require("helper/share");
var saleCount = ui("do_Label_3");
var productSpec = ui("do_ALayout_10");
var selectSpecText = ui("do_Label_13");
var shopUi = ui("shopUi");
var shopImage = ui("shopImage");
var shopName = ui("shopName");
var shopUserNick = ui("shopUserNick");
var helperOpen = require("helper/open");
var imHelper = require("helper/im");
//页面装载完成后，开始初始化工作
var sIndex = 1;
var specDataList = [];
var shareTitle="",shareContent="",shareImage="",shareId,shareType;
page.on("productDetailBox", function(data){
	var vo = data;
	specDataList = vo.productSpecLst;
	if(specDataList.length <= 1){
		productSpec.visible = false; 
	}else{
		productSpec.visible = true; 
		selectSpecText.text = specDataList[0].color + specDataList[0].specName +" x 1";
	}
	if(vo.mallShopVo == null){
		shopUi.visible = false; 
	}else{
		shopUi.visible = true; 
		var shopVo = vo.mallShopVo;
		shopImage.source = shopVo.fullLogo;
		shopName.text = shopVo.name;
		shopName.tag = shopVo.id;
		shopUserNick.text = shopVo.userNick;
		shopUserNick.tag = shopVo.creatorId;
	}
	//图片
	var imgs = vo.imgItems;
	var jsonImgs = [];
	for (var j = 0; j < imgs.length; j++) {
		jsonImgs.push({
			"template" : 0,
			"imgs" : imgs[j].source
		});
	}
	labelSindex.text = sIndex;
	lableScount.text = imgs.length;
	imgData.addData(jsonImgs);
	imgView.bindItems(imgData);
	imgView.refreshItems();
	productNameLabel.text = vo.name;
	priceLabel.text = vo.price;
	unitLabel.text = vo.unit;
	marketPriceLabel.text = "￥"+vo.marketPrice;
	saleCount.text = "已售"+vo.saleCount;
	if(vo.subtitle){
		ui("do_LinearLayout_4").visible = true;
		labelSubtitle.text = vo.subtitle;
	}
	shareTitle=vo.name;
	shareContent=vo.name;
	shareId=vo.id;
	shareType=shareHelper.type.MALL_PRODUCT;
});

imgView.on("indexChanged", function(data, e) {
	sIndex = data+1;
	labelSindex.text = data+1;
});

productSpec.on("touch", "", 300, function() {
	page.hideKeyboard();
	page.fire("productSpecList", specDataList);
	page.fire("productSpec", "true");
});

//选择规格后返回刷新
page.on("refreshSpecText",function(data){
	selectSpecText.text = data;
});
//选择规格后返回刷新
page.on("refreshSpec",function(data){
	priceLabel.text = data.price;
	unitLabel.text = data.unit;
	marketPriceLabel.text = "￥"+data.markPrice;
});
ui("do_ALayout_6").on("touch", "", 300, function() {
	page.fire("onShare",{showView:"true",shareTitle:shareTitle,shareContent:shareContent,shareId:shareId,shareType:shareType,shareImage:shareImage});
});

ui("shopNameALayout").on("touch", "", 300, function() {
	page.hideKeyboard();
	if (shopName.tag != null && shopName.tag != 1) {
		helperOpen.open("source://view/qshop/detail/main.ui",{shopId:shopName.tag});
	}
});
ui("shopImageALayout").on("touch", "", 300, function() {
	page.hideKeyboard();
	if (shopName.tag != null && shopName.tag != 1) {
		helperOpen.open("source://view/qshop/detail/main.ui",{shopId:shopName.tag});
	}
});
ui("intoShopALayout").on("touch", "", 300, function() {
	page.hideKeyboard();
	if (shopName.tag != null && shopName.tag != 1) {
		helperOpen.open("source://view/qshop/detail/main.ui",{shopId:shopName.tag});
	}
});
ui("callShopUserALayout").on("touch", "", 300, function() {
	page.hideKeyboard();
	if (shopUserNick.tag != null) {
		imHelper.toChat(shopUserNick.tag);
	}
});
ui("shopUserNickALayout").on("touch", "", 300, function() {
	page.hideKeyboard();
	if (shopUserNick.tag != null) {
		helperOpen.openPersonal(shopUserNick.tag);
	}
});